package cc.coolplay51.fakashop3.Handler;


import cc.coolplay51.fakashop3.DO.Msg;
import cc.coolplay51.fakashop3.Utils.LogUtil;
import cc.coolplay51.fakashop3.Utils.MsgUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Classname GlobalExceptionHandler
 * @Description TODO
 * @Date 2020/10/28 15:18
 * @Created by HanYuHao
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /***
     * @Description: 全局错误返回
     * @Param: [e]
     * @return: Msg
     * @Author: HanYuHao
     * @Date: 2020/10/28
     */
    @ResponseBody
    @ExceptionHandler
    public Msg Handle(Exception e) {
        LogUtil.e("检测到错误发生");
        e.printStackTrace();
        LogUtil.e("错误信息 Error Message",e.getMessage());
        LogUtil.e("错误原因 Error Cause",e.getCause());
        return MsgUtil.fail(e.getMessage());
    }
}
